/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.tutorial.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.biz.modular.course.entity.EduCourse;
import vip.xiaonuo.biz.modular.course.service.EduCourseService;
import vip.xiaonuo.biz.modular.klass.entity.EduKlass;
import vip.xiaonuo.biz.modular.klass.service.EduKlassService;
import vip.xiaonuo.biz.modular.lecture.entity.EduLecture;
import vip.xiaonuo.biz.modular.lecture.enums.EduLectureStateEnum;
import vip.xiaonuo.biz.modular.lecture.service.EduLectureService;
import vip.xiaonuo.biz.modular.teacher.entity.EduTeacher;
import vip.xiaonuo.biz.modular.teacher.service.EduTeacherService;
import vip.xiaonuo.biz.modular.tutorial.param.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import vip.xiaonuo.biz.modular.tutorial.entity.EduTutorial;
import vip.xiaonuo.biz.modular.tutorial.service.EduTutorialService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 配课控制器
 *
 * @author ahui
 * @date  2023/05/26 19:06
 */
@Api(tags = "配课控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@RestController
@Validated
public class EduTutorialController {

    @Resource
    private EduTutorialService eduTutorialService;

    @Resource
    private EduKlassService eduKlassService;

    @Resource
    private EduCourseService eduCourseService;

    @Resource
    private EduTeacherService eduTeacherService;

    @Resource
    private EduLectureService eduLectureService;

    /**
     * 获取配课分页
     *
     * @author ahui
     * @date  2023/05/26 19:06
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取配课分页")
    @SaCheckPermission("/biz/tutorial/page")
    @GetMapping("/biz/tutorial/page")
    public CommonResult<Page<EduTutorial>> page(EduTutorialPageParam eduTutorialPageParam) {
        return CommonResult.data(eduTutorialService.page(eduTutorialPageParam));
    }

    /**
     * 添加配课
     *
     * @author ahui
     * @date  2023/05/26 19:06
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加配课")
    @CommonLog("添加配课")
    @SaCheckPermission("/biz/tutorial/add")
    @PostMapping("/biz/tutorial/add")
    public CommonResult<String> add(@RequestBody @Valid EduTutorialAddParam eduTutorialAddParam) {
        eduTutorialService.add(eduTutorialAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑配课
     *
     * @author ahui
     * @date  2023/05/26 19:06
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑配课")
    @CommonLog("编辑配课")
    @SaCheckPermission("/biz/tutorial/edit")
    @PostMapping("/biz/tutorial/edit")
    public CommonResult<String> edit(@RequestBody @Valid EduTutorialEditParam eduTutorialEditParam) {
        eduTutorialService.edit(eduTutorialEditParam);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("批量编辑")
    @CommonLog("批量编辑")
    @SaCheckPermission("/biz/tutorial/edit")
    @PostMapping("/biz/tutorial/batchEdit")
    public CommonResult<String> batchEdit(@RequestBody @Valid EduTutorialBatchEditParam eduTutorialBatchEditParam) {
        eduTutorialService.batchEdit(eduTutorialBatchEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除配课
     *
     * @author ahui
     * @date  2023/05/26 19:06
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除配课")
    @CommonLog("删除配课")
    @SaCheckPermission("/biz/tutorial/delete")
    @PostMapping("/biz/tutorial/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<EduTutorialIdParam> eduTutorialIdParamList) {
        eduTutorialService.delete(eduTutorialIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取配课详情
     *
     * @author ahui
     * @date  2023/05/26 19:06
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取配课详情")
    @SaCheckPermission("/biz/tutorial/detail")
    @GetMapping("/biz/tutorial/detail")
    public CommonResult<EduTutorial> detail(@Valid EduTutorialIdParam eduTutorialIdParam) {
        return CommonResult.data(eduTutorialService.detail(eduTutorialIdParam));
    }

    /**
     * 获取课程选择器
     * @return ahui
     * * @date  2023/05/13 21:39
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("获取课程选择器")
    //@SaCheckPermission("/biz/tutorial/courseList")
    @GetMapping("/biz/tutorial/courseList")
    public CommonResult<List<EduCourse>> courseSelector() {
        return CommonResult.data(eduCourseService.list());
    }

    /**
     * 获取教师选择器
     * @return ahui
     * * @date  2023/05/13 21:39
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("获取教师选择器")
    //@SaCheckPermission("/biz/tutorial/teacherList")
    @GetMapping("/biz/tutorial/teacherList")
    public CommonResult<List<EduTeacher>> teacherSelector() {
        return CommonResult.data(eduTeacherService.list());
    }

    /**
     * 获取班级选择器
     * @return ahui
     * * @date  2023/05/13 21:39
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("获取班级选择器")
    //@SaCheckPermission("/biz/tutorial/klassList")
    @GetMapping("/biz/tutorial/klassList")
    public CommonResult<List<EduKlass>> klassSelector() {
        return CommonResult.data(eduKlassService.list());
    }

    /**
     * 配课导出
     *
     * @author xuyuxiang
     * @date 2022/4/24 20:00
     */
    @ApiOperationSupport(order = 8)
    @ApiOperation("配课导出")
    @CommonLog("配课导出")
    @GetMapping(value = "/biz/tutorial/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void export(EduTutorialExportParam eduTutorialExportParam, HttpServletResponse response) throws IOException {
        eduTutorialService.exportTutorial(eduTutorialExportParam, response);
    }

    /**
     * 拆班
     *
     * @author xuyuxiang
     * @date 2022/4/24 20:00
     */
    @ApiOperationSupport(order = 9)
    @ApiOperation("拆班")
    @CommonLog("拆班")
    @GetMapping(value = "/biz/tutorial/splitClass")
    public CommonResult<String> splitClass(EduTutorialExportParam eduTutorialExportParam){
        eduTutorialService.splitClass(eduTutorialExportParam);
        return CommonResult.ok();
    }
}
